/*
 * @Author: zxh
 * @Email: 1271027008@qq.com
 * @Date: 2020-03-18 11:30:14
 * @Descripttion: 
 */

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-my-todo-list',
  templateUrl: './my-todo-list.component.html',
  styleUrls: ['./my-todo-list.component.scss']
})
export class MyTodoListComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

  sender:string = ''
  processName:string = ''
  statusList = [
    {
      id:0,
      name:'未读'
    },
    {
      id:1,
      name:'已读'
    },
    {
      id:3,
      name:'已完成'
    }
  ]
  dateStart = ''
  dateEnd = ''
  onStart(start){
    console.log(start)
  }
  onEnd(end){
    console.log(end)
  }
  // table
  listOfAllData = [
    {
      id:1,
      code:'123',
      processCode:'456',
      processName:'aaa',
      time:'2020-03-19',
      sender:'wewew',
      status:'未读'
    }
  ]
  isAllDisplayDataChecked = false;
  isIndeterminate = false;
  listOfDisplayData = [];
  mapOfCheckedId: { [key: string]: boolean } = {};
  numberOfChecked = 0;

  currentPageDataChange($event): void {
    this.listOfDisplayData = $event;
    this.refreshStatus();
  }
  refreshStatus(): void {
    this.isAllDisplayDataChecked = this.listOfDisplayData.every(item => this.mapOfCheckedId[item.id]);
    if (this.listOfAllData.length == 0) {
      this.isAllDisplayDataChecked = false
    }
    this.isIndeterminate =
      this.listOfDisplayData.some(item => this.mapOfCheckedId[item.id]) && !this.isAllDisplayDataChecked;
    this.numberOfChecked = this.listOfAllData.filter(item => this.mapOfCheckedId[item.id]).length;
  }
  checkAll(value: boolean): void {
    this.listOfDisplayData.forEach(item => (this.mapOfCheckedId[item.id] = value));
    this.refreshStatus();
  }

}
